class {$#model_name} extends lmbActiveRecordTreeNode
{
  protected $_db_table_name = '{$#table_name}';
  protected $_tree;

<? if(count($this->lazy_attributes)) { ?>  protected $_lazy_attributes = array('<? echo implode('\', \'', $this->lazy_attributes); ?>');<? echo "\n\r"; } ?>

<? if($this->relations_exist) { ?>  protected function _defineRelations()
  {
<? if($this->has_many) { ?>    $this->_has_many = {$#has_many|raw};<? echo "\n\r"; } ?>
<? if($this->many_belongs_to) { ?>    $this->_many_belongs_to = {$#many_belongs_to|raw};<? echo "\n\r"; } ?>
<? if($this->has_one) { ?>    $this->_has_one = {$#has_one|raw};<? echo "\n\r"; } ?>
<? if($this->belongs_to) { ?>    $this->_belongs_to = {$#belongs_to|raw};<? echo "\n\r"; } ?>
<? if($this->has_many_to_many) { ?>    $this->_has_many_to_many = {$#has_many_to_many|raw};<? echo "\n\r"; } ?>
  }

<? } ?>

  protected function _createValidator()
  {
    $validator = new lmbValidator();

    $validator->addRequiredRule('title', 'Поле "Заголовок" обязательно для заполнения');
    $validator->addRequiredRule('identifier', 'Поле "Идентификатор" обязательно для заполнения');
    
    lmb_require('limb/validation/src/rule/lmbPatternRule.class.php');
    $validator->addRule(new lmbPatternRule("identifier", "/^[a-zA-Z0-9-_]+$/i", 'Поле "Идентификатор" может содержать только цифры, символы латинского алфавита и символы `-` и `_`'));

    return $validator;
  }                                                       

  function _onCreate()
  {
    $this->_setPriority();
  }

  protected function _setPriority()
  {
    if(!$parent_id = $this->getParentId()) 
      $parent_id = {$#model_name} :: findRoot()->getId();

    $sql = "SELECT MAX(priority) FROM " . $this->_db_table_name . " WHERE parent_id = " . $parent_id;
    $max_priority = lmbDBAL :: fetchOneValue($sql);
    $this->setPriority($max_priority + 10);
  }

  function getUri()
  {
    return  '{$#model_url}' .$this->getTree()->getPathToNode($this->getId());
  }
}
